package cn.java63.biz2;

import cn.java63.biz.User;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Aspect
public class UserServiceLoggerAno {
    @Around("within(cn.java63.biz2..*)")
    public Object lanjie(ProceedingJoinPoint jp) throws Throwable{
        /*if(jp.getSignature().getName().equals("del")){
            long id=(long)jp.getArgs()[0];
            if(id==1){
                throw new Exception("不能删除");
            }
        }*/

        if(jp.getSignature().getName().equals("search")) {
            List<User> list=(List)jp.proceed();//放行
            for(int i=0;i<list.size();i++){
                if(list.get(i).getName().equals("admin")){
                    list.remove(i);
                    i--;
                }
            }
            return list;
        }
        long start=System.nanoTime();
        Object o=jp.proceed();//放行
        long end=System.nanoTime();
        System.out.println("执行时间"+(end-start)+"返回值"+o);
        return o;
    }
}
